﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using VisualCode.Client;

namespace VisualCode.Forms
{
    /// <summary>
    /// Interaction logic for MainWin.xaml
    /// </summary>
    public partial class MainWin : Window
    {
        public MainWin()
        {
            InitializeComponent();

            Populate();
        }

        private VisualProject _project;

        private void Populate()
        {
            ObservableCollection<VisualProject> projects = new ObservableCollection<VisualProject>();

            //Create the project
            VisualProject project = new VisualProject();
            project.Name = "ACME.Client";
            project.OutputType = AssemblyOutputType.ClassLibrary;

            // Create a namespace
            VisualNamespace visualNamespace = new VisualNamespace();
            visualNamespace.Name = "AMCE.Client";
            project.Namespaces.Add(visualNamespace);
            projects.Add(project);

            //Create a class
            VisualClass customerClass = new VisualClass();
            customerClass.Name = "Customer";

            VisualField visualField = new VisualField();
            visualField.Name = "CustomerID";
            visualField.Type = new VisualTypeReference(typeof(Int32));
            customerClass.Fields.Add(visualField);

            visualNamespace.Types.Add(customerClass);

            //Create another class
            VisualClass orderClass = new VisualClass();
            orderClass.Name = "Order";

            VisualField orderIdField = new VisualField();
            orderIdField.Name = "OrderId";
            orderIdField.Type = new VisualTypeReference(typeof(Int32));
            orderClass.Fields.Add(orderIdField);

            visualNamespace.Types.Add(orderClass);

            SolutionExplorerTreeView.ItemsSource = projects;

            _project = project;

        }

        private void BuildSolution_Click(object sender, RoutedEventArgs e)
        {
            OutputTextBox.Clear();

            OutputTextBox.AppendText("Starting build..." + Environment.NewLine);

            using (VisualCompiler compiler = new VisualCompiler(_project))
            {
                compiler.Compile();
            }

            OutputTextBox.AppendText("Build complete." + Environment.NewLine);
        }
    }
}
